package com.inossem.warehousestorage_inossem.request.allocation;

import android.content.Context;

import com.google.gson.Gson;
import com.inossem.warehousestorage_inossem.bean.allocation.AllocationInSubmitBean;
import com.inossem.warehousestorage_inossem.bean.allocation.AllocationOutSubmitBean;
import com.inossem.warehousestorage_inossem.bean.allocation.AllocationOutSubmitRequestBean;
import com.inossem.warehousestorage_inossem.constant.RequestConstant;
import com.inossem.warehousestorage_inossem.listener.GsonBeanListener;
import com.inossem.warehousestorage_inossem.listener.StringRequestListener;
import com.inossem.warehousestorage_inossem.manage.RequestManage;
import com.inossem.warehousestorage_inossem.model.StringResponse;
import com.inossem.warehousestorage_inossem.request.Request;

/**
 * TODO
 *
 * @author 詹建宇
 * @time on 2018/4/9 15:16
 * @email jianyu.zhan@inossem.com
 */
public class AllocationOutSubmitRequest extends Request {

    public static String request(Context context, AllocationOutSubmitRequestBean bean, String requestType, GsonBeanListener gsonBeanListener) {
        String tag;
        String url = RequestManage.getUrl(context, RequestConstant.URL_ALLOCATION_OUT_SUBMIT);

        Gson gson= new Gson();
        String json = gson.toJson(bean);

        switch (requestType) {
            case "0":
                tag = RequestManage.getHttpsPostWithLoading(context, url, json, new StringRequestListener() {
                    @Override
                    public void onSuccess(StringResponse stringRequestResponse) {
                        Gson gson = new Gson();
                        AllocationOutSubmitBean bean = gson.fromJson(stringRequestResponse.getResponseInfo(), AllocationOutSubmitBean.class);
                        excuteJsonBeanNew(context, bean, gsonBeanListener);
                    }
                });
                break;
            default:
                tag = RequestManage.getHttpsPutWithLoading(context, url, json, new StringRequestListener() {
                    @Override
                    public void onSuccess(StringResponse stringRequestResponse) {
                        Gson gson = new Gson();
                        AllocationOutSubmitBean bean = gson.fromJson(stringRequestResponse.getResponseInfo(), AllocationOutSubmitBean.class);
                        excuteJsonBeanNew(context, bean, gsonBeanListener);
                    }
                });
                break;
        }
        return tag;
    }

}
